﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using proRFID_DiemDanh.Chung;
using System.Data;
using System.Data.SqlClient;

namespace proRFID_DiemDanh.Lop
{
    public class mdLop
    {
        public static DataTable Khoa_DDL()
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_Khoa_DDL", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }

        public static DataTable lop_select(int malop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_lop_select", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@malop", malop);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable lop_khoacbo(int makhoa)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_lop_khoacbo", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@makhoa", makhoa);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable lop_insert(int makhoa, string tenlop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_lop_insert", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;           
            cmd.Parameters.AddWithValue("@makhoa", makhoa);
            cmd.Parameters.AddWithValue("@tenlop", tenlop);          
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable lop_update(int malop, int makhoa, string tenlop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_lop_update", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@malop", malop);
            cmd.Parameters.AddWithValue("@makhoa", makhoa);
            cmd.Parameters.AddWithValue("@tenlop", tenlop);            
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable lop_delete(int malop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_lop_delete", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@malop", malop);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        //Danh sách lớp
        public static DataTable DSlop_select(int malop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_DSlop_select", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@malop", malop);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable DSlop_chuyen(string masv,int malop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_DSLop_chuyen", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@masv", masv);
            cmd.Parameters.AddWithValue("@malop", malop);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable DSlop_chuyencbo(int malop)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_DSLop_chuyencbo", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;           
            cmd.Parameters.AddWithValue("@malop", malop);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable dslop_dssvkhonglop()
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_dslop_dssvkhonglop ", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;            
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable DSLop_insert(int malop,string masv)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_DSLop_insert ", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@malop", malop);
            cmd.Parameters.AddWithValue("@masv", masv);            
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
    }
}